<template>
  <!-- 昨日采购入库数据报告 -->
  <div class="TodayPurchaseDatacontent">
    <div class="TodayPurchaseDatacontent1">
      <div id="leftPie" class="leftPie" />
      <div id="rightPie" class="rightPie" />
    </div>
    <div class="btmTlt">
      <span class="btmTlt12">采购</span><span class="btmTlt12">入库</span>
    </div>
  </div>
</template>

<script>
import tools from "@/utils/tools"; //引入tools.js
import { getYesterdayInOut } from "@/api/user";
import * as echarts from "echarts/core";
import { TitleComponent } from "echarts/components";
import { PieChart } from "echarts/charts";
import { LabelLayout } from "echarts/features";
import { CanvasRenderer } from "echarts/renderers";

echarts.use([TitleComponent, PieChart, CanvasRenderer, LabelLayout]);
export default {
  name: "TodayPurchaseData",
  data() {
    return {};
  },
  mounted() {
    this.getYesterdayInOut();
  },
  beforeDestroy() {},
  methods: {
    async getYesterdayInOut() {
      const res = await getYesterdayInOut();
      if (res.code === 200) {
        console.log(res.data, "昨日采购入库数据报告");
        this.$nextTick(() => {
          this.initChart(res.data.buyList, res.data.buySum);
          this.initChart2(res.data.inboundList, res.data.inboundSum);
        });
      }
    },
    initChart(data1, sum) {
      const chartDom1 = document.getElementById("leftPie");
      const myChart1 = echarts.init(chartDom1);
      const option1 = {
        title: {
          zlevel: 0,
          text: [sum],
          top: "center",
          left: "48%",
          textAlign: "center",
          textStyle: {
            color: "#F6F6F6",
            fontSize: 10,
            lineHeight: 28,
          },
        },
        color: ["#7EFDD7", "#38CAFB", "#5094FF", "#2470FB"],
        series: [
          {
            name: "Access From",
            type: "pie",
            radius: ["25%", "70%"],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 1,
              borderWidth: 1,
              shadowBlur: 3,
              shadowOffsetX: 1,
            },
            labelLine: {
              show: true,
              length: 5,
              length2: 25,
            },
            label: {
              position: "outside",
              fontSize: 8,
              color: "#BDD1FF",
              formatter: "{b}\n{c}",
              // formatter: '{a|{b}\n{d}%}\n{hr|}',
              lineHeight: 15,
            },
            data: data1,
            minAngle: 30,
          },
        ],
      };
      option1 && myChart1.setOption(option1);
      myChart1.dispatchAction({
        type: "highlight",
        name: ["日用品", "其他", "食品干货"], // 可以通过name指定，或者数据项的 index
      });
      // tools.autoHover(myChart1, option1, 4, 2000);
    },
    initChart2(data1, sum) {
      const chartDom = document.getElementById("rightPie");
      const myChart = echarts.init(chartDom);
      // const total = 5401;
      const option = {
        title: {
          zlevel: 0,
          text: [sum],
          top: "center",
          left: "48%",
          textAlign: "center",
          textStyle: {
            color: "#F6F6F6",
            fontSize: 10,
            lineHeight: 28,
          },
        },
        color: ["#3CF24B", "#2471FE", "#E7EA5E", "RGBA(127, 255, 217, 1)"],
        series: [
          {
            name: "Access From",
            type: "pie",
            radius: ["25%", "70%"],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 1,
              borderWidth: 1,
              shadowBlur: 3,
              shadowOffsetX: 1,
            },
            labelLine: {
              show: true,
              length: 5,
              length2: 25,
            },
            label: {
              position: "outside",
              fontSize: 8,
              color: "#BDD1FF",
              formatter: "{b}\n{c}",
              // formatter: '{a|{b}\n{d}%}\n{hr|}',
              lineHeight: 15,
            },
            data: data1,
            minAngle: 30,
          },
        ],
      };
      option && myChart.setOption(option);
      myChart.dispatchAction({
        type: "highlight",
        name: ["日用品", "其他", "食品干货"], // 可以通过name指定，或者数据项的 index
      });
      // tools.autoHover(myChart, option, 4, 2000);
    },
  },
};
</script>

<style scoped lang="scss">
.TodayPurchaseDatacontent {
  width: 2.6328rem;
  height: 1.1745rem;
  .TodayPurchaseDatacontent1 {
    color: aliceblue;
    padding: 0.1302rem 0.1042rem 0;
    display: flex;
    justify-content: start;
    width: 2.6328rem;
    height: 90%;
    .leftPie {
      width: 50%;
      height: 100%;
    }
    .rightPie {
      width: 50%;
      height: 100%;
    }
  }
  .btmTlt {
    height: 10%;
    color: #fff;
    display: flex;
    font-size: 0.0625rem;
    font-weight: bold;
    .btmTlt12 {
      width: 50%;
      text-align: center;
    }
  }
}
</style>
